import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Demo3 {

    private static BlockingQueue<Integer> blockingQueue = new LinkedBlockingQueue<>(100);

    public static void main(String[] args) {

        Thread creat = new Thread(() -> {

            int p = 0;


                try {
                    while (true) {
//                        Thread.sleep(1000);

                        blockingQueue.put(p);
                        System.out.println("生产者生产：" + p);
                        p++;
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }


        },"cre");

        Thread colunm = new Thread(() -> {

                try {
                    while (true) {

//                        Thread.sleep(1000);
                        int p = blockingQueue.take();

                        System.out.println("消费者消费：" + p);
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

        },"col");

        creat.start();
        colunm.start();
    }
}
